package com.tjy.service.impl;

import com.tjy.bean.MobilePhone;
import com.tjy.bean.PageBean;
import com.tjy.bean.PageQuery;
import com.tjy.dao.IMobilePhoneByPageDao;
import com.tjy.service.IMobilePhoneByPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IMobilePhoneByPageServiceImpl implements IMobilePhoneByPageService {
    @Autowired
    private IMobilePhoneByPageDao mobilePhoneByPageDao;

    @Resource
    private PageBean<MobilePhone> pageBean;
    @Override
    public PageBean selectMobilePhoneByPage(Integer currentPage) {

//        PageBean<MobilePhone> pageBean = new PageBean<>();
        pageBean.setCurrentPage(currentPage);//设置当前页数

        Integer pageSize=5;
        pageBean.setPageSize(pageSize);//设置每页记录数

       Integer totalSize = mobilePhoneByPageDao.selectTotaiSize();
        pageBean.setTotalSize(totalSize);//设置总记录数

        Integer totalPage = totalSize % pageSize == 0 ? totalSize / pageSize : totalSize / pageSize+1;
        pageBean.setTotalPage(totalPage);//设置总页数

        Integer begin =(currentPage -1) * pageSize;
       List<MobilePhone> list = mobilePhoneByPageDao.selectList(new PageQuery(begin,pageSize));
        pageBean.setList(list);
        return pageBean;
    }





}
